import http from "@/api";
import {
  selectGoodsListRetType,
  GoodCategoryListType,
  AddEditFormDataType,
  LaboratoryListType,
  ExportExcelConditionDataType,
  selectGoodsLabListType,
  lendReturnLogByPageType
} from "./type";
import qs from "qs";
import { downImportTempUrl } from "@/libs/down";

// 使用枚举包含所有的Path
enum Api {
  // 分页查询货品列表
  selectTbGoodsByPage = "/tbGoods/selectByPage",
  // 查询类别列表
  selectCategoryList = "/tbGoodsCategory/select",
  // 查询实验室列表
  selectLaboratoryList = "/tbLab/selectList",
  // 查询货品详情信息
  selectGoodDetailInfo = "",
  // 添加货品
  addTbGoods = "/tbGoods/add",
  // 编辑货品
  editTbGoods = "/tbGoods/edit",
  // 删除货品
  deleteTbGoods = "/tbGoods/delete",
  // 导出Excel
  exportExcel = "/tbGoods/exportTbGoods",
  // 下载导入模版
  downImportTemp = "" + downImportTempUrl,
  // 查询所有实验室
  selectAllLab = "/tbLab/selectAll",
  // 查询当前用户可以查询货品的实验室列表
  tbLabSelectByGoods = "/tbLab/selectByGoods",
  // 借出货品
  lendTbGoods = "/tbGoods/lendTbGoods",
  // 归还货品
  returnTbGoods = "/tbGoods/returnTbGoods",
  // 查询借出/归还日志
  selectByTbGoodsId = "/lendReturn/selectByTbGoodsId"
}

// 分页查询货品列表的Api
export const selectTbGoodsByPageApi = (data: {
  page: number;
  size: number;
  labAddress: string;
  code: string;
  name: string;
  categoryName: string;
  subjectName: string;
  projectName: string;
}) => {
  let dataQ = "?" + qs.stringify(data);
  return http.post<selectGoodsListRetType>(Api.selectTbGoodsByPage + dataQ, {}, { loading: false });
};

// 查询类别列表的Api
export const selectCategoryListApi = () => {
  return http.post<GoodCategoryListType>(Api.selectCategoryList, {}, { loading: false });
};

// 查询实验室列表的Api
export const selectLaboratoryListApi = () => {
  return http.post<LaboratoryListType>(Api.selectLaboratoryList, {}, { loading: false });
};

// 添加货品的Api
export const addTbGoodsApi = (data: AddEditFormDataType) => {
  let dataQ = "?" + qs.stringify(data);
  return http.post(Api.addTbGoods + dataQ, {}, { loading: false });
};

// 编辑货品的Api
export const editTbGoodsApi = (data: AddEditFormDataType) => {
  let dataQ = "?" + qs.stringify(data);
  return http.post(Api.editTbGoods + dataQ, {}, { loading: false });
};

// 删除货品的Api
export const deleteGoodsApi = (id: number) => {
  let dataQ = "?" + qs.stringify({ id: id });
  return http.post(Api.deleteTbGoods + dataQ, {}, { loading: false });
};

// 导出Excel的Api
export const exportExcelApi = (data: ExportExcelConditionDataType) => {
  let dataQ = "?" + qs.stringify(data);
  return http.download(Api.exportExcel + dataQ, {}, { loading: false });
};

// 下载导入Excel模版的Api
export const downImportTempApi = () => {
  return http.download(Api.downImportTem, {}, { loading: false });
};

// 查询所有实验室的Api
export const selectAllLabApi = () => {
  return http.post<string[]>(Api.selectAllLab, {}, { loading: false });
};

// 查询当前用户可以查询货品的实验室列表的Api
export const tbLabSelectByGoodsApi = () => {
  return http.post<selectGoodsLabListType>(Api.tbLabSelectByGoods, {}, { loading: false });
};

// 借出货品的Api
export const lendTbGoodsApi = data => {
  return http.post(Api.lendTbGoods, data, { loading: false });
};

// 归还货品的Api
export const returnTbGoodsApi = data => {
  return http.post(Api.returnTbGoods, data, { loading: false });
};

// 查询借出归还日志的Api
export const lendGoodsSubListApi = data => {
  let dataQ = "?" + qs.stringify(data);
  return http.post<lendReturnLogByPageType>(Api.selectByTbGoodsId + dataQ, {}, { loading: false });
};
